package cn.school.servlet;

import cn.school.dao.StudentMapper;
import cn.school.entity.Student;
import cn.school.service.StudentService;
import cn.school.util.MybatisUtil;
import cn.school.util.StringUtil;
import cn.school.vo.Page;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
//@WebServlet(name = "studentServlet",urlPatterns = "/student")
@WebServlet( value = "/studentServlet",loadOnStartup = 1)
public class StudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int pageNo= StringUtil.toInt(req.getParameter("pageNo"),1);
        String sname=req.getParameter("sname");
        String qq=req.getParameter("qq");
        String phone=req.getParameter("phone");
        req.setAttribute("sname",StringUtil.trim(sname));
        req.setAttribute("qq",StringUtil.trim(qq));
        req.setAttribute("phone",StringUtil.trim(phone));
        Page<Student> p = StudentService.INST.search(pageNo, Page.PAGE_SIZE, sname, qq, phone, null, null);
        req.setAttribute("p",p);
        req.getRequestDispatcher("/WEB-INF/jsp/student/student.jsp").forward(req,resp);
    }
}
